package org.vetc.mgr.adapter.viewholder

import org.itzheng.itplayer.adapter.viewholder.VHRecyclerAdapter

/**
 * Title:<br></br>
 * Description: <br></br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2020-7-30.
 */
abstract class VHKotlinAdapter : VHRecyclerAdapter() {
    private val mItems = mutableListOf<Any>()
    override fun getItemCount(): Int {
        return mItems?.size ?: 0
    }

    /**
     * 重置
     */
    fun <T> submitList(list: List<T>?) {
        mItems.clear()
        //清空数据然后添加
        if (list != null) {
            addItems(list)
        }

    }

    /**
     * 添加更多
     */
    fun <T> addItems(list: List<T>?) {
        if (list != null) {
            for (item in list) {
                mItems.add(item!!)
            }
            notifyDataSetChanged()
        }

    }

    /**
     * 移除item
     */
    fun removeItem(item: Any): Int {
        val index = mItems.indexOf(item)
        mItems.remove(item)
        return index
    }

    fun getItems(): MutableList<Any> {
        return mItems;
    }

    /**
     * 获取数据，如果没有的话，返回空，因为使用加载更多，目前有bug
     */
    fun getItem(position: Int): Any? {
        val temp = mItems
        if (temp.size <= position) {
            return null
        }
        return temp.get(position)
    }
}